-- Leviathan (c) v.v.balashoff
local audioList = require('audio/list')
local Class = require('leviathan/Class')
local Log = require('leviathan/Log')

local AudioManager = Class:derive('AudioManager')

function AudioManager:new()
    self.audio = {}
end

function AudioManager:getAudio(fileName)
    local r = nil
    local info
    -- check audio list
    local path = audioList[fileName]
    -- get audio
    if not self.audio[path] then
        local a = {}
        a.name = fileName
        a.path = path
        if not a.path then
            Log:error('[AudioManager] Cannot find audio file: '..tostring(a.path))
            Log:error('[AudioManager] filename: '..fileName)
            os.exit()
        end
        a.file = love.filesystem.newFileData(a.path)
        if not a.file then
            Log:error('[AudioManager] Audio not found: '..path)
            os.exit()
        end
        info = love.filesystem.getInfo(a.path)
        Log:debug('[AudioManager] Audio loaded: '..path..': '..math.floor(info.size/1000)..' kB')
        -- adding to array
        self.audio[path] = a
    end
    r = self.audio[path]
    return r
end

return AudioManager
